// 导航守卫
export default function (router) {
  router.beforeEach((to, from, next) => { 
    console.log('to', to);  
    console.log('from', from);  
      
    if (to.path === '/load' || to.path === '/login') {  
      if ( sessionStorage.getItem('load')){
        next('/login');
       sessionStorage.removeItem('load');
      } else {  
        next();
      }  
      return;  
    }
    

    if (to.meta.auth) {  
      if (!localStorage.getItem('token')) {
        next('/login');  
        if (typeof ElMessage === 'function') {
          ElMessage({  
            message: '身份验证失败,请重新登录',  
            type: 'warning',  
          });  
        }  
      } else {  
        next();  
      }  
    } else {  
      next();  
    }  
  });


}
